﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Forum.Entity.Post;
using Frame.Lib.Core.Base;

namespace Forum.DAL.Post
{
    public class ForumTopicDAL : BaseDAL
    {

        ///// <summary>
        ///// 获取本版非置顶贴（审核通过的）
        ///// </summary>
        ///// <param name="boardID"></param>
        ///// <param name="currentPage">从1开始</param>
        ///// <param name="pageSize"></param>
        ///// <returns></returns>
        //public List<ForumTopicInfo> GetNormalList(int boardID, int currentPage, int pageSize, out int recordCount)
        //{
        //    string condition = " BoardID=@p0 and TopLevel=0 and IsDisplay=1 ";
        //    string orderby = " order by  LastPostTime desc ";
        //    int begin = (currentPage - 1) * pageSize + 1;
        //    int end = begin + pageSize -1;

        //    recordCount = dbOper.GetScalar<int>("select count(*) from ForumTopic where " + condition, boardID);

        //    string sql = "select * from (" +
        //                 "select row_number() over (" + orderby + ") as RowID, * from ForumTopic where " + condition +
        //                 ") as t where RowID between " + begin + " and " + end;
        //    List<ForumTopicInfo> list = dbOper.Query<ForumTopicInfo>(sql, boardID);
        //    return list;
        //}

        /// <summary>
        /// 获取置顶贴，包括全局置顶和版块置顶
        /// </summary>
        /// <param name="boardID"></param>
        /// <returns></returns>
        public List<ForumTopicInfo> GetTopList(int boardID)
        {
            string sql = "select * from ForumTopic where TopLevel=" + (int)ForumTopicTopLevel.Global + " or (TopLevel = " + (int)ForumTopicTopLevel.Board + " and BoardID=@p0 and IsDisplay=1) order by TopLevel desc, LastPostTime desc";
            List<ForumTopicInfo> list = dbOper.Query<ForumTopicInfo>(sql, boardID);
            return list;
        }
    }

}
